package com.yowasa.xiuxian.engine.battle.enemy.strategy;

import com.google.common.collect.Lists;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.engine.battle.strategy.CalAbility;
import com.yowasa.xiuxian.engine.battle.strategy.InherentStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.InherentTiming;
import org.springframework.core.annotation.Order;

import java.util.List;

@BS(name="上善若水")
@Order(-1000)
public class ShangShanRuoShui extends CalAbility implements InherentStrategy {
    @Override
    public ElementEnum getElement() {
        return ElementEnum.WOOD;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int cmp = first.getBattleInfo().getCmp()*first.getBattleInfo().getRestoreRate()/100;
        int spell = (first.getBattleInfo().getHp()/20)*first.getBattleInfo().getRestoreRate()/100;
        int needHp = first.getBattleInfo().getHp() - first.getBattleInfo().getChp();
        List<Integer> nums = Lists.newArrayList(cmp, spell, needHp);
        nums.sort(Integer::compareTo);
        Integer can = nums.get(0);
        int cost=can * 100 / first.getBattleInfo().getRestoreRate();
        first.getBattleInfo().setChp(first.getBattleInfo().getChp() + can);
        first.getBattleInfo().setCmp(first.getBattleInfo().getCmp() - cost);
        content.getMsgLog().add(first.getUserBO().getName() + "因上善若水回复" + can + "点血量");
    }

    @Override
    public void limit(UserBO user) { }
    @Override
    public String limitDesc() {
        return "无";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        if (user.getBattleInfo().getChp() >= user.getBattleInfo().getHp()) {
            return false;
        }
        if (user.getBattleInfo().getCmp() <= 0) {
            return false;
        }
        return true;
    }

    @Override
    public String desc() {
        return "自己行动开始时消耗等量mp最高回复5%最大生命值的血量";
    }

    @Override
    public List<InherentTiming> getTiming() {
        return Lists.newArrayList(InherentTiming.SELF_BEGIN);
    }


}
